<template>
  <div>
    <!-- <el-button
      @click="clickBtn"
      plain
      style="position: absolute"
      type="single-number"
    >
      选择
    </el-button> -->
    <el-dialog
      :visible.sync="dialogTableVisibletextarea"
      custom-class="sorting-code-number"
      maxHeight="null"
      title="选择验收单"
      width="990px"
      :before-close="beforeClose"
    >
      <div class="el-dialog__body-header">
        <span class="title"></span>
        <el-search
          :formProp="formDate"
          :showIndex="showIndex"
          @change="change"
          @search="search"
          placement="bottom-start"
          width="420px"
        >
          <template slot="search">
            <el-input
              clearable
              placeholder="请输入验收单名称模糊查询"
              searchLabel="验收单名称"
              v-model="formDate.acceptanceName"
            ></el-input>
            <el-input
              clearable
              placeholder="请输入验收单编号编号模糊查询"
              searchLabel="验收单编号"
              v-model="formDate.acceptanceNumber"
            ></el-input>

            <el-input
              clearable
              placeholder="请输入供应商模糊查询"
              searchLabel="供应商"
              v-model="formDate.supplier"
            ></el-input>
            <el-input
              clearable
              placeholder="请输入填报单位模糊查询"
              searchLabel="填报单位"
              v-model="formDate.reportInOrgName"
            ></el-input>
            <el-input
              clearable
              placeholder="请输入验收人模糊查询"
              searchLabel="验收人"
              v-model="formDate.acceptor"
            ></el-input>
          </template>
        </el-search>
      </div>
      <div class="el-dialog__body-bodys">
        <div class="bodys-right">
          <el-table
            :data="tableData"
            :fit="true"
            :lineClamp="lineClampBody"
            maxHeight="390"
            style="width: 950px"
          >
            <el-table-column label="序号" width="50">
              <template slot-scope="scope">
                <span>{{ scope.$index + 1 }}</span>
              </template>
            </el-table-column>
            <template v-for="(table, index) in unfixedTableThead">
              <el-table-column
                :fixed="table.fixed || false"
                :key="index"
                :type="table.type"
                :label="table.label"
                :align="table.align || 'left'"
                :header-align="table.headerAlign || 'left'"
                :min-width="table.width"
                :prop="table.prop"
                :show-overflow-tooltip="true"
                border="true"
              >
              </el-table-column>
            </template>
            <el-table-column label="操作" width="70">
              <template slot-scope="scope" style="margin-top: -11px">
                <el-button
                  :class="scope.row.button === false ? '' : 'checked'"
                  @click="handleClick(scope.row)"
                  plain
                  size="mini"
                  type="single-number-filleted"
                  >{{ scope.row.button === false ? "选择" : "已选择" }}
                </el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listAcceptanceCert } from "../api/bowOut";
import { setSessionItem } from "@/basa/utils";
import { formatNumber } from "../../../../basa/utils";

export default {
  props: {
    partBdata: {
      type: Array,
      default() {
        return [];
      }
    },
    partyAId: {
      type: Number
    },
    reportInOrgId: {
      type: Number
    }
  },
  data() {
    return {
      showIndex: 0,
      lineClampBody: true,
      tableData: [],
      searchData: [],
      treeProps: {
        label: "name",
        children: "zones",
        isLeaf: "leaf"
      },
      dialogTableVisibletextarea: false,
      formDate: {
        acceptanceNumber: "", //验收单编号
        acceptanceName: "", //验收单名称
        supplier: "", //供应商
        reportInOrgName: "", //填报单位
        acceptor: "" //验收人
      },
      textarea: "",
      formLabelWidth: "120px",
      //   pageSizeCode: 5,
      //   pageNoCode: 1,
      present: "",
      TableData: "",
      //   total: 0,
      //   totalNum: 0,
      lastTime: {
        button: false
      },
      //   pagesize: [5],
      unfixedTableThead: [
        { prop: "acceptanceNumber", label: "验收单编号" },
        { prop: "acceptanceName", label: "验收单名称" },
        { prop: "supplier", label: "供应商" },
        { prop: "acceptor", label: "验收人" },
        { prop: "reportInOrgName", label: "填报单位" },
        { prop: "acceptanceCurrentNumber", label: "验收数量" }
      ],
      formDataSearch: {}
    };
  },
  watch: {
    partBdata(data) {
      this.tableData = data;
    },
    partyAId(data) {
      this.formDate.orgid = data;
    }
  },
  created() {},
  methods: {
    beforeClose() {
      this.resetData();
      this.dialogTableVisibletextarea = false;
    },
    resetData() {
      this.listConSupPage();
    },
    inventoryConfirm() {
      this.dialogTableVisibletextarea = false;
      // alert(JSON.stringify(this.TableData));
      this.$emit("inventoryConfirm", this.TableData);
    },
    listConSupPage() {
      listAcceptanceCert({
        ...this.formDate,
        reportInOrgId: this.reportInOrgId,
        moduleType: "bowOut",
        businessType: "1"
      }).then(res => {
        this.tableData = res.data.data;
        this.tableData.map(e => {
          e.acceptanceCurrentNumber = formatNumber(
            e.acceptanceCurrentNumber,
            3
          );
          e.button = false;
          //   if (this.TableData.id === e.id) {
          //     console.log('object')
          //     e.button = true;
          //   }
        });
      });
    },
    handleClick(val) {
      console.log(val);
      this.TableData = val;
      val.button = true;
      if (val.id !== this.lastTime.id) {
        this.lastTime.button = false;
        this.lastTime = val;
      }
      console.log(val.button);
      this.tableData = [...this.tableData];

      this.dialogTableVisibletextarea = false;

      this.$emit("partyBName", val);
      //   this.$bus.$emit("partyBValue", val);
    },
    search(searchData) {
      this.formDataSearch = searchData;
      this.localSearchData = JSON.parse(JSON.stringify(searchData));
      setSessionItem("pageNo", this.tableName, {
        searchForm: this.localSearchData
      });
      this.listConSupPage(this.formDataSearch);
    },
    change(index, key, value) {
      this.showIndex = index;
    }
  }
};
</script>
<style lang="scss" scoped>
// /deep/ .el-searchs-right > .el-input {
//   width: 200px;
// }
/deep/ .el-input .el-pagination__editor .is-in-pagination {
  width: 80px !important;
}
</style>
